﻿@using YueQian.ShortUrl.Extensions
@{
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
<script type="text/javascript" src="~/Scripts/My97DatePicker/WdatePicker.js"></script>

<div class="row-fluid">
    <p>
        <button class="btn btn-primary" onclick="op.add()"><i class="icon-glass"></i>新增广告位</button>
    </p>
    <div class="row-fluid" id="add" style="display: none;">
        <div class="widget-box">
            <div class="widget-header">
                <h4>广告位详情</h4>
            </div>
            <div class="widget-body">
                <form class="form-horizontal" id="data-form">
                    <div class="control-group">
                        <input type="hidden" name="Id" id="Id" value="0" />
                        <input type="hidden" name="PositionNumber" id="PositionNumber" value="" />
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="Name">名称</label>
                        <div class="controls">
                            <input type="text" id="Name" name="Name" placeholder="名称" />
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="Price">价格</label>
                        <div class="controls">
                            <input type="text" id="Price" name="Price" placeholder="价格" />
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="Width">宽度</label>
                        <div class="controls">
                            <input type="text" id="Width" name="Width" placeholder="宽度" />
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="Height">高度</label>
                        <div class="controls">
                            <input type="text" id="Height" name="Height" placeholder="高度" />
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="Contents">描述</label>
                        <div class="controls">
                            <textarea class="span8 limited" id="Contents" name="Contents" data-maxlength="120" maxlength="120"></textarea>
                        </div>
                    </div>
                    <div class="form-actions">
                        <button class="btn btn-info" type="submit"><i class="icon-ok"></i>提交</button>
                        &nbsp; &nbsp; &nbsp;
                        <button class="btn" type="reset" onclick="op.addcancel()"><i class="icon-undo"></i>取消</button>
                    </div>
                </form>
            </div>
        </div>
        <div class="hr"></div>
    </div>
    <div class="row-fluid">
        <div class="table-header">
        </div>
        <div class="toolbar">
            <form class="form-horizontal" id="searchForm">
                <div class="control-group">
                    <span>关键词:</span><input type="text" name="keyword" id="keyword" class="input" />
                    <span>更新时间:</span><input type="text" name="periodtime" id="periodtime" style="width: 175px;" />
                    <button type="button" onclick="op.search();" class="btn btn-small btn-primary" style="margin-left: 10px;">搜 索</button>
                    <button type="reset" class="btn btn-small btn-inverse" style="margin-left: 20px;">重 置</button>
                </div>
            </form>
        </div>
        <table id="dataTable" class="table table-hover table-nomargin table-striped table-bordered">
            <thead>
                <tr>
                    <th style="width: 10px;">
                        <label>
                            <input type="checkbox" id="check_all" /><span class="lbl"></span>
                        </label>
                    </th>
                    <th style="width: 120px;">编号</th>
                    <th style="width: 100px;">名称</th>
                    <th style="width: 180px;">大小</th>
                    <th style="width: 100px;">价格</th>
                    <th>描述</th>
                    <th style="width: 140px;">更新时间</th>
                    <th style="width: 100px;">操作</th>
                </tr>
            </thead>
            <tbody></tbody>
        </table>
    </div>
</div>
<link href="~/Content/admin/css/daterangepicker.css" rel="stylesheet" />
<script type="text/javascript" src="/Content/admin/js/moment.min.js"></script>
<script type="text/javascript" src="/Content/admin/js/daterangepicker.js"></script>
<script type="text/javascript" src="/Content/admin/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/Content/admin/js/jquery.dataTables.bootstrap.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script type="text/javascript">
    var op = {
        add: function () {
            $("#add").slideDown();
        },
        edit: function (id) {
            $.post("/System/AdvertisementPositionInfo", { eId: id }, function (data) {
                if (data.result) {
                    $("#Id").val(data.model.Id);
                    $("#PositionNumber").val(data.model.PositionNumber);
                    $("#Name").val(data.model.Name);
                    $("#Price").val(data.model.Price);
                    $("#Width").val(data.model.Width);
                    $("#Height").val(data.model.Height);
                    $("#Description").text(data.model.Description);
                    $("#add").slideDown();
                }
                else {
                    alert(data.model);
                    return false;
                }
            }, "Json");
        },
        addcancel: function () {
            $("#Id").val("0");
            $("#PositionNumber").val("");
            $("#Name").val("");
            $("#Price").val("");
            $("#Width").val("");
            $("#Height").val("");
            $("#Description").text("");
            $("#add").slideUp();
        },
        init: function () {

            $('#periodtime').daterangepicker();

            $("#data-form").validate({
                errorElement: "span",
                errorClass: "invalid",
                rules: {
                    Name: { required: true },
                    Price: { required: true, number: true },
                    Width: { required: true, number: true },
                    Height: { required: true, number: true },
                },
                messages: {
                    Name: { required: "请填写名称" },
                    Price: { required: "价格", number: "请填写一个数字" },
                    Width: { required: "宽度", number: "请填写一个数字" },
                    Height: { required: "高度", number: "请填写一个数字" },
                },
                submitHandler: function (form) {
                    $.post("/System/AdvertisementPositionInfo", $("#data-form").serialize(),
                        function (data) {
                            alert(data.msg);
                            if (data.result)
                                window.location.href = "/System/AdvManager/Position";
                            return false;
                        }, "Json");
                }
            });

            this.search();
        },

        search: function () {
            $("#dataTable").dataTable().fnDestroy();
            $('#dataTable').dataTable({
                "bProcessing": true,
                "bSort": false,
                "bServerSide": true,
                "iDisplayLength": 20,
                "bPaginate": true,
                "aoColumns": [
                    { "mDataProp": "CheckBox" },
                    { "mDataProp": "PositionNumber" },
                    { "mDataProp": "Name" },
                    { "mDataProp": "Detail" },
                    { "mDataProp": "Price" },
                    { "mDataProp": "Description" },
                    { "mDataProp": "CreationDate" },
                    { "mDataProp": "Operate" }
                ],
                "sAjaxSource": "/System/AdvPositionList?cach=" + Math.random(),
                "sServerMethod": "POST",
                "fnServerParams": function (aoData) {
                    aoData.push({
                        "name": "keyword",
                        "value": $("#keyword").val()
                    }),
                    aoData.push({
                        "name": "StartTime",
                        "value": $("#periodtime").val().split('-')[0] || "@(DateTime.MinValue.ToString())"
                    }),
                    aoData.push({
                        "name": "EndTime",
                        "value": $("#periodtime").val().split('-')[1] || "@(DateTime.Now.ToString())"
                    })
                },
                "pagingType": "full_numbers",
                "bFilter": false,
                "sDom": 'frtip'
            });
        }
    }

    $(function () { op.init(); })
</script>
